
from DB_demo.models import Gwas
# from DB_demo.models import MrResult


from DB_demo.models import MrResultAll58465E8
from DB_demo.models import Papers
from DB_demo.models import PaperNew
from DB_demo.models import Mrdis2Dis1E5
from DB_demo.models import Mrdis2Dis5E6
from DB_demo.models import Mrdis2Dis5E8
from DB_demo.models import Mreqtl2Dis1E5
from DB_demo.models import Mreqtl2Dis5E6
from DB_demo.models import Mreqtl2Dis5E8
from DB_demo.models import Mrpqtl2Dis1E5
from DB_demo.models import Mrpqtl2Dis5E6
from DB_demo.models import Mrpqtl2Dis5E8
from DB_demo.models import Pubdis2Dis
from DB_demo.models import Pubeqtl2Dis
from DB_demo.models import Pubpqtl2Dis,  DownloadpageSingle, Metabolitename

from DB_demo.models import Mrall, Phewas, RsidPos, MrallCombine, AllexposureName, AlloutcomeName

from DB_demo.models import Disname, DisnameOutcome, Cpgsitename
from DB_demo.models import Genename, GenenameOutcome
from DB_demo.models import Proteinname, ProteinnameOutcome

from rest_framework import serializers

from DB_demo.models import MrallDisdis, MrallPqtldis, MrallEqtldis


class AllexposureNameSerializer(serializers.ModelSerializer):
    class Meta:
        model = AllexposureName
        fields = '__all__'


class AlloutcomeNameSerializer(serializers.ModelSerializer):
    class Meta:
        model = AlloutcomeName
        fields = '__all__'


class GwasSerializer(serializers.ModelSerializer):
    class Meta:
        model = Gwas
        fields = '__all__'


# class MrResultSerializer(serializers.ModelSerializer):
#     class Meta:
#         model = MrResult
#         fields = '__all__'


class MrResultAll58465E8Serializer(serializers.ModelSerializer):
    class Meta:
        model = MrResultAll58465E8
        fields = '__all__'


class PapersSerializer(serializers.ModelSerializer):
    class Meta:
        model = Papers
        fields = '__all__'


class PapersNewSerializer(serializers.ModelSerializer):
    class Meta:
        model = PaperNew
        fields = '__all__'


class Mrdis2Dis1E5Serializer(serializers.ModelSerializer):
    class Meta:
        model = Mrdis2Dis1E5
        fields = '__all__'


class Mrdis2Dis5E6Serializer(serializers.ModelSerializer):
    class Meta:
        model = Mrdis2Dis5E6
        fields = '__all__'


class Mrdis2Dis5E8Serializer(serializers.ModelSerializer):
    class Meta:
        model = Mrdis2Dis5E8
        fields = '__all__'


class Mreqtl2Dis1E5Serializer(serializers.ModelSerializer):
    class Meta:
        model = Mreqtl2Dis1E5
        fields = '__all__'


class Mreqtl2Dis5E6Serializer(serializers.ModelSerializer):
    class Meta:
        model = Mreqtl2Dis5E6
        fields = '__all__'


class Mreqtl2Dis5E8Serializer(serializers.ModelSerializer):
    class Meta:
        model = Mreqtl2Dis5E8
        fields = '__all__'


class Mrpqtl2Dis1E5Serializer(serializers.ModelSerializer):
    class Meta:
        model = Mrpqtl2Dis1E5
        fields = '__all__'


class Mrpqtl2Dis5E6Serializer(serializers.ModelSerializer):
    class Meta:
        model = Mrpqtl2Dis5E6
        fields = '__all__'


class Mrpqtl2Dis5E8Serializer(serializers.ModelSerializer):
    class Meta:
        model = Mrpqtl2Dis5E8
        fields = '__all__'


class Pubdis2DisSerializer(serializers.ModelSerializer):
    class Meta:
        model = Pubdis2Dis
        fields = '__all__'


class Pubeqtl2DisSerializer(serializers.ModelSerializer):
    class Meta:
        model = Pubeqtl2Dis
        fields = '__all__'


class Pubpqtl2DisSerializer(serializers.ModelSerializer):
    class Meta:
        model = Pubpqtl2Dis
        fields = '__all__'

# -----------------------------
class MrallSerializer(serializers.ModelSerializer):
    class Meta:
        model = Mrall
        fields = '__all__'


class MrallCombineSerializer(serializers.ModelSerializer):
    fdr = serializers.FloatField(required=False)  # 添加 fdr 字段

    class Meta:
        model = MrallCombine
        fields = '__all__'


class DownpagesingleSerializer(serializers.ModelSerializer):
    class Meta:
        model = DownloadpageSingle
        fields = '__all__'

# 2024 9 05


class MetabolitenameSerializer(serializers.ModelSerializer):
    class Meta:
        model = Metabolitename
        fields = '__all__'


class CpgsitenameSerializer(serializers.ModelSerializer):
    class Meta:
        model = Cpgsitename
        fields = '__all__'


class MrallDisdisSerializer(serializers.ModelSerializer):
    class Meta:
        model = MrallDisdis
        fields = '__all__'


class MrallPqtldisSerializer(serializers.ModelSerializer):
    class Meta:
        model = MrallPqtldis
        fields = '__all__'


class MrallEqtldisSerializer(serializers.ModelSerializer):
    class Meta:
        model = MrallEqtldis
        fields = '__all__'


class UniversalMrallSerializer(serializers.ModelSerializer):
    class Meta:
        fields = '__all__'

    def to_representation(self, instance):
        """
        Object instance -> Dict of primitive datatypes.
        """
        # Since the instance could be from any of the three models, we need to dynamically
        # set the model to the Meta class to ensure the correct fields are used.
        self.Meta.model = type(instance)
        return super().to_representation(instance)


class DisnameSerializer(serializers.ModelSerializer):
    class Meta:
        model = Disname
        fields = ['name']  # 只序列化 'name' 字段
        # fields = '__all__'


class DisnameOutcomeSerializer(serializers.ModelSerializer):
    class Meta:
        model = DisnameOutcome
        fields = ['name']  # 只序列化 'name' 字段
        # fields = '__all__'


class GenenameSerializer(serializers.ModelSerializer):
    class Meta:
        model = Genename
        fields = '__all__'


class GenenameOutcomeSerializer(serializers.ModelSerializer):
    class Meta:
        model = GenenameOutcome
        fields = '__all__'


class ProteinnameOutcomeSerializer(serializers.ModelSerializer):
    class Meta:
        model = ProteinnameOutcome
        fields = '__all__'


class ProteinnameSerializer(serializers.ModelSerializer):
    class Meta:
        model = Proteinname
        fields = '__all__'


class RsidPosSerializer(serializers.ModelSerializer):
    class Meta:
        model = RsidPos
        fields = '__all__'


class PhewasSerializer(serializers.ModelSerializer):
    class Meta:
        model = Phewas
        fields = '__all__'


class Phewas2Serializer(serializers.ModelSerializer):
    class Meta:
        model = Phewas
        fields = ('traits', 'pval', 'gwasid', 'beta')

